//
// Created by 夏申频 on 16/9/15.
//

#ifndef JPEGBITCOMMON_H
#define JPEGBITCOMMON_H

#ifndef LIBJPEGBIT
#define LIBJPEGBIT 8
#endif

#ifndef NAME_SPACE_TMP
#define NAME_SPACE_TMP(BIT) JPEG##BIT
#endif

#if LIBJPEGBIT == 8
extern "C" {
#include <libjpeg/8/jinclude.h>
#include <libjpeg/8/jpeglib.h>
#include <libjpeg/8/jerror.h>
}
#define JPEG_NAME_SPACE NAME_SPACE_TMP(8)
#elif LIBJPEGBIT == 12
extern "C" {
#include <libjpeg/12/jinclude.h>
#include <libjpeg/12/jpeglib.h>
#include <libjpeg/12/jerror.h>
}
#define JPEG_NAME_SPACE NAME_SPACE_TMP(12)
#elif LIBJPEGBIT ==16
extern "C" {
#include <libjpeg/16/jinclude.h>
#include <libjpeg/16/jpeglib.h>
#include <libjpeg/16/jerror.h>
}
#define JPEG_NAME_SPACE NAME_SPACE_TMP(16)
#endif

#define DECLARE_GETTER_SETTER_TMP(TYPE,NAME,ZERO) virtual TYPE NAME () ZERO; virtual void NAME ( TYPE v) ZERO;
#define DECLARE_GETTER_SETTER_INTERFACE(TYPE,NAME)  DECLARE_GETTER_SETTER_TMP(TYPE,NAME,=0)
#define DECLARE_GETTER_SETTER(TYPE,NAME)  DECLARE_GETTER_SETTER_TMP(TYPE,NAME,;)
#define IMPL_GETTER_SETTER(TYPE,NAME,CLASS,FIELD) \
    TYPE CLASS::NAME(){return FIELD.NAME;}\
    void CLASS::NAME(TYPE v){ FIELD.NAME = v;}

#define IMPL_DECODER_GETTER_SETTER(TYPE,NAME) IMPL_GETTER_SETTER(TYPE,NAME,Decoder,dc)
#define IMPL_ENCODER_GETTER_SETTER(TYPE,NAME) IMPL_GETTER_SETTER(TYPE,NAME,Encoder,cc)

#include <iostream>
#include <csetjmp>
#include <vector>
#ifndef JPEGPP_INTERFACE_H
#define JPEGPP_INTERFACE_H
namespace JPEG{


    const int CODER_BIT_INCOMPATIBLE = 1025;

    class CoderCommon;
    class Decoder;
    class Encoder;

    typedef std::vector<JOCTET> ImageBuf;

    class ImageCodecErrorHandler{
    public:
        virtual void onError(CoderCommon* coder) = 0;
        virtual ~ImageCodecErrorHandler() = 0;
    };

    class LongJumpErrorHandler:public ImageCodecErrorHandler {
    public:
        std::jmp_buf setjmp_buffer;
        virtual void onError(CoderCommon* coder);
        virtual ~LongJumpErrorHandler() ;
    };

    class ImageInputStream{
    public:
        virtual ~ImageInputStream() =0 ;
        virtual int available() =0;
        virtual int read(ImageBuf& buf,size_t offset,size_t len)=0;
    };

    class ImageOutputStream{
    public:
        virtual ~ImageOutputStream() =0 ;
        virtual void write(const ImageBuf& buf,size_t offset,size_t len)=0;
        virtual void flush() = 0;
    };

    class STDImageInputStream:public ImageInputStream{
    private:
        std::istream& iStream;
    public:
        STDImageInputStream(std::istream& istream);
        virtual ~STDImageInputStream();
        virtual int available();
        virtual int read(ImageBuf& buf,size_t offset,size_t len);
    };

    class STDImageOutputStream:public ImageOutputStream{
    private:
        std::ostream& oStream;
    public:
        STDImageOutputStream(std::ostream& os);
        virtual ~STDImageOutputStream();
        virtual void write(const ImageBuf& buf,size_t offset,size_t len);
        virtual void flush();
    };

    class CoderCommon{
    public:
        virtual void setErrorHandler(ImageCodecErrorHandler* errorHandler)=0;
        virtual int start() = 0;
        virtual int finish() = 0;
        virtual void close() = 0;
        virtual void error(int code)=0;
        virtual void warn(int code)=0;
        virtual std::string lastErrorMsg() = 0;
        virtual int lastErrorCode() = 0;
        virtual ~CoderCommon() =0;
    };

    class Decoder:public CoderCommon{
    public:
        virtual int readHeader(bool require_image)= 0;
        virtual int readScanLines(int lines,ImageOutputStream* out)= 0;
        virtual void setInput(ImageInputStream* input)= 0;
        virtual ~Decoder() =0;

        DECLARE_GETTER_SETTER_INTERFACE(JDIMENSION ,image_width)  /* nominal image width (from SOF marker) */
        DECLARE_GETTER_SETTER_INTERFACE(JDIMENSION ,image_height)  /* nominal image height */
        DECLARE_GETTER_SETTER_INTERFACE(int ,num_components)    /* # of color components in JPEG image */
        DECLARE_GETTER_SETTER_INTERFACE(J_COLOR_SPACE ,jpeg_color_space) /* colorspace of JPEG image */
        DECLARE_GETTER_SETTER_INTERFACE(J_COLOR_SPACE ,out_color_space) /* colorspace for output */
        DECLARE_GETTER_SETTER_INTERFACE(unsigned int ,scale_num)
        DECLARE_GETTER_SETTER_INTERFACE(unsigned int,scale_denom) /* fraction by which to scale image */
        DECLARE_GETTER_SETTER_INTERFACE(double ,output_gamma)    /* image gamma wanted in output */
        DECLARE_GETTER_SETTER_INTERFACE(boolean ,buffered_image)  /* TRUE=multiple output passes */
        DECLARE_GETTER_SETTER_INTERFACE(boolean ,raw_data_out)    /* TRUE=downsampled data wanted */
        DECLARE_GETTER_SETTER_INTERFACE(J_DCT_METHOD ,dct_method)  /* IDCT algorithm selector */
        DECLARE_GETTER_SETTER_INTERFACE(boolean ,do_fancy_upsampling)  /* TRUE=apply fancy upsampling */
        DECLARE_GETTER_SETTER_INTERFACE(boolean ,do_block_smoothing)  /* TRUE=apply interblock smoothing */
        DECLARE_GETTER_SETTER_INTERFACE(boolean ,quantize_colors)  /* TRUE=colormapped output wanted */
        DECLARE_GETTER_SETTER_INTERFACE(J_DITHER_MODE ,dither_mode)  /* type of color dithering to use */
        DECLARE_GETTER_SETTER_INTERFACE(boolean ,two_pass_quantize)  /* TRUE=use two-pass color quantization */
        DECLARE_GETTER_SETTER_INTERFACE(int ,desired_number_of_colors)  /* max # colors to use in created colormap */
        DECLARE_GETTER_SETTER_INTERFACE(boolean ,enable_1pass_quant)  /* enable future use of 1-pass quantizer */
        DECLARE_GETTER_SETTER_INTERFACE(boolean ,enable_external_quant)/* enable future use of external colormap */
        DECLARE_GETTER_SETTER_INTERFACE(boolean ,enable_2pass_quant)  /* enable future use of 2-pass quantizer */
        DECLARE_GETTER_SETTER_INTERFACE(JDIMENSION ,output_width)  /* scaled image width */
        DECLARE_GETTER_SETTER_INTERFACE(JDIMENSION ,output_height)  /* scaled image height */
        DECLARE_GETTER_SETTER_INTERFACE(int ,out_color_components)  /* # of color components in out_color_space */
        DECLARE_GETTER_SETTER_INTERFACE(int ,output_components)  /* # of color components returned */
        DECLARE_GETTER_SETTER_INTERFACE(int ,rec_outbuf_height)  /* min recommended height of scanline buffer */
        DECLARE_GETTER_SETTER_INTERFACE(int ,actual_number_of_colors)  /* number of entries in use */
        DECLARE_GETTER_SETTER_INTERFACE(JDIMENSION ,output_scanline)  /* 0 .. output_height-1  */
        DECLARE_GETTER_SETTER_INTERFACE(int ,input_scan_number)  /* Number of SOS markers seen so far */
        DECLARE_GETTER_SETTER_INTERFACE(JDIMENSION ,input_iMCU_row)  /* Number of iMCU rows completed */
        DECLARE_GETTER_SETTER_INTERFACE(int ,output_scan_number)  /* Nominal scan number being displayed */
        DECLARE_GETTER_SETTER_INTERFACE(JDIMENSION ,output_iMCU_row)  /* Number of iMCU rows read */
        DECLARE_GETTER_SETTER_INTERFACE(int ,data_precision)    /* bits of precision in image data */
        DECLARE_GETTER_SETTER_INTERFACE(boolean ,saw_JFIF_marker)  /* TRUE iff a JFIF APP0 marker was found */
        DECLARE_GETTER_SETTER_INTERFACE(UINT8 ,JFIF_major_version)  /* JFIF version number */
        DECLARE_GETTER_SETTER_INTERFACE(UINT8 ,JFIF_minor_version)
        DECLARE_GETTER_SETTER_INTERFACE(UINT8 ,density_unit)    /* JFIF code for pixel size units */
        DECLARE_GETTER_SETTER_INTERFACE(UINT16 ,X_density)    /* Horizontal pixel density */
        DECLARE_GETTER_SETTER_INTERFACE(UINT16 ,Y_density)    /* Vertical pixel density */
        DECLARE_GETTER_SETTER_INTERFACE(boolean ,saw_Adobe_marker)  /* TRUE iff an Adobe APP14 marker was found */
        DECLARE_GETTER_SETTER_INTERFACE(UINT8 ,Adobe_transform)  /* Color transform code from Adobe marker */
        DECLARE_GETTER_SETTER_INTERFACE(boolean ,CCIR601_sampling)  /* TRUE=first samples are cosited */
        DECLARE_GETTER_SETTER_INTERFACE(int ,data_unit)    /* size of data unit in samples */
        DECLARE_GETTER_SETTER_INTERFACE(J_CODEC_PROCESS ,process)  /* decoding process of JPEG image */
        DECLARE_GETTER_SETTER_INTERFACE(int ,max_h_samp_factor)  /* largest h_samp_factor */
        DECLARE_GETTER_SETTER_INTERFACE(int ,max_v_samp_factor)  /* largest v_samp_factor */
        DECLARE_GETTER_SETTER_INTERFACE(int ,min_codec_data_unit)  /* smallest codec_data_unit of any component */
        DECLARE_GETTER_SETTER_INTERFACE(JDIMENSION ,total_iMCU_rows)  /* # of iMCU rows in image */
        DECLARE_GETTER_SETTER_INTERFACE(JDIMENSION, MCUs_per_row)  /* # of MCUs across the image */
        DECLARE_GETTER_SETTER_INTERFACE(JDIMENSION ,MCU_rows_in_scan)  /* # of MCU rows in the image */
        DECLARE_GETTER_SETTER_INTERFACE(int ,data_units_in_MCU)  /* # of data _units per MCU */
        DECLARE_GETTER_SETTER_INTERFACE(int,Ss)
        DECLARE_GETTER_SETTER_INTERFACE(int ,Se)
        DECLARE_GETTER_SETTER_INTERFACE(int ,Ah)
        DECLARE_GETTER_SETTER_INTERFACE(int,Al)    /* progressive/lossless JPEG parms for scan */
        DECLARE_GETTER_SETTER_INTERFACE(int,unread_marker)

    };

    class Encoder:public CoderCommon{
    public:
        virtual void setOutput(ImageOutputStream* output) = 0;
        virtual int writeScanLines(int lines,ImageInputStream* in) = 0;

        virtual void setDefault()=0;

        virtual void quality(int v)=0;
        virtual void lossy(bool l)=0;

        virtual ~Encoder() =0;

        DECLARE_GETTER_SETTER_INTERFACE(JDIMENSION,image_width);
        DECLARE_GETTER_SETTER_INTERFACE(JDIMENSION,image_height);
        DECLARE_GETTER_SETTER_INTERFACE(J_COLOR_SPACE,in_color_space);
        DECLARE_GETTER_SETTER_INTERFACE(int,input_components);
        DECLARE_GETTER_SETTER_INTERFACE(double,input_gamma);
        DECLARE_GETTER_SETTER_INTERFACE(boolean,lossless);
        DECLARE_GETTER_SETTER_INTERFACE(int,data_precision);
        DECLARE_GETTER_SETTER_INTERFACE(int,num_components)    /* # of color components in JPEG image */
        DECLARE_GETTER_SETTER_INTERFACE(J_COLOR_SPACE ,jpeg_color_space) /* colorspace of JPEG image */
        DECLARE_GETTER_SETTER_INTERFACE(int ,num_scans)    /* # of entries in scan_info array */
        DECLARE_GETTER_SETTER_INTERFACE(boolean ,raw_data_in)    /* TRUE=caller supplies downsampled data */
        DECLARE_GETTER_SETTER_INTERFACE(boolean, arith_code)    /* TRUE=arithmetic coding, FALSE=Huffman */
        DECLARE_GETTER_SETTER_INTERFACE(boolean, optimize_coding)  /* TRUE=optimize entropy encoding parms */
        DECLARE_GETTER_SETTER_INTERFACE(boolean, CCIR601_sampling)  /* TRUE=first samples are cosited */
        DECLARE_GETTER_SETTER_INTERFACE(int, smoothing_factor)    /* 1..100, or 0 for no input smoothing */
        DECLARE_GETTER_SETTER_INTERFACE(unsigned int,restart_interval) /* MCUs per restart, or 0 for no restart */
        DECLARE_GETTER_SETTER_INTERFACE(int,restart_in_rows)    /* if > 0, MCU rows per restart interval */
        DECLARE_GETTER_SETTER_INTERFACE(boolean,write_JFIF_header)  /* should a JFIF marker be written? */
        DECLARE_GETTER_SETTER_INTERFACE(UINT8,JFIF_major_version)  /* What to write for the JFIF version number */
        DECLARE_GETTER_SETTER_INTERFACE(UINT8,JFIF_minor_version)
        DECLARE_GETTER_SETTER_INTERFACE(UINT8,density_unit)    /* JFIF code for pixel size units */
        DECLARE_GETTER_SETTER_INTERFACE(UINT16,X_density)    /* Horizontal pixel density */
        DECLARE_GETTER_SETTER_INTERFACE(UINT16,Y_density)    /* Vertical pixel density */
        DECLARE_GETTER_SETTER_INTERFACE(boolean,write_Adobe_marker)  /* should an Adobe marker be written? */
        DECLARE_GETTER_SETTER_INTERFACE(JDIMENSION,next_scanline)  /* 0 .. image_height-1  */
        DECLARE_GETTER_SETTER_INTERFACE(int,data_unit)    /* size of data unit in samples */
        DECLARE_GETTER_SETTER_INTERFACE(J_CODEC_PROCESS,process)  /* encoding process of JPEG image */
        DECLARE_GETTER_SETTER_INTERFACE(int,max_h_samp_factor)  /* largest h_samp_factor */
        DECLARE_GETTER_SETTER_INTERFACE(int,max_v_samp_factor)  /* largest v_samp_factor */
        DECLARE_GETTER_SETTER_INTERFACE(JDIMENSION,total_iMCU_rows)  /* # of iMCU rows to be input to codec */
        DECLARE_GETTER_SETTER_INTERFACE(int,comps_in_scan)    /* # of JPEG components in this scan */
        DECLARE_GETTER_SETTER_INTERFACE(JDIMENSION,MCUs_per_row)  /* # of MCUs across the image */
        DECLARE_GETTER_SETTER_INTERFACE(JDIMENSION,MCU_rows_in_scan)  /* # of MCU rows in the image */
        DECLARE_GETTER_SETTER_INTERFACE(int,data_units_in_MCU)  /* # of data units per MCU */
        DECLARE_GETTER_SETTER_INTERFACE(int ,Ss)
        DECLARE_GETTER_SETTER_INTERFACE(int,Se);
        DECLARE_GETTER_SETTER_INTERFACE(int,Ah);
        DECLARE_GETTER_SETTER_INTERFACE(int,Al);    /* progressive/lossless JPEG parameters for scan */
    };

    Decoder* jpegDecoder(int bit);
    Encoder* jpegEncoder(int bit);

    int putValueToImageBuf(ImageBuf& buf,size_t pos,JOCTET value);
    int putValueToImageBuf(ImageBuf& buf,size_t pos,JOCTET* buffer,size_t bufferSize);
    const JOCTET* getImageBufPointer(const ImageBuf& buf);
};

#endif

namespace JPEG_NAME_SPACE {

    class CoderCommon;
    class SourceManager;
    class Decoder;
    class Encoder;

    class ErrorManager{
    private:
        struct jpeg_error_mgr pub;
        JPEG::ImageCodecErrorHandler* errorHandler;
    public:
        ErrorManager(JPEG::ImageCodecErrorHandler*);
        virtual ~ErrorManager();
        jpeg_error_mgr * error_mgr();
        JPEG::ImageCodecErrorHandler* getErrorHandler() const ;
        //std::jmp_buf setjmp_buffer;
        //virtual void onError(JPEG::CoderCommon* coder);
    };

    class SourceManager{
    protected:
        jpeg_source_mgr* pub;
        static const int readBufferSize ;
        JPEG::ImageBuf readBuf;
        JPEG::ImageInputStream* iis;
        bool flag;
        bool startOfFile;
    protected:
        static void init_source_handler(j_decompress_ptr cinfo);
        static boolean fill_input_buffer_handler(j_decompress_ptr cinfo);
        static void skip_input_data_handler(j_decompress_ptr cinfo, long num_bytes);
        static void term_source_handler(j_decompress_ptr cinfo);
        static boolean reSync_to_restart_handler(j_decompress_ptr cinfo, int desired);
    public:

        virtual void initSource(Decoder* decoder);
        virtual bool fillInputBuffer(Decoder* decoder);
        virtual void skipInputData(Decoder* decoder, long num_bytes);
        virtual void termSource(Decoder* decoder);
        virtual bool reSyncToRestart(Decoder* decoder, int desired);

        SourceManager(Decoder* decoder,JPEG::ImageInputStream* stream);
        virtual ~SourceManager();
        jpeg_source_mgr* sourceMgr();

        void init(Decoder* decoder,JPEG::ImageInputStream* stream);

        virtual bool isFlag() const;
        virtual void setFlag(bool flag);
    };

    class DestinationManager{
    private:
        jpeg_destination_mgr* pub;
        JPEG::ImageOutputStream* ios;
        static const int writeBufferSize;
        JPEG::ImageBuf writeBuf;
    protected:
        static void init_destination (j_compress_ptr cinfo);
        static boolean empty_output_buffer (j_compress_ptr cinfo);
        static void term_destination (j_compress_ptr cinfo);
    public:
        DestinationManager(Encoder* encoder,JPEG::ImageOutputStream* ios);
        ~DestinationManager();
        void init(Encoder* encoder,JPEG::ImageOutputStream* outputStream);

        virtual void initDestination (Encoder* encoder);
        virtual boolean emptyOutputBuffer (Encoder* encoder);
        virtual void termDestination (Encoder* encoder);


    };

    class CoderCommon :public JPEG::CoderCommon {
    private:
        j_common_ptr cInfo;
    protected:
        ErrorManager* errorManager;
        JPEG::ImageBuf* image_buffer;
        int row_stride;
        virtual j_common_ptr init_private() = 0;
    public:

        static void error_handler(j_common_ptr cinfo);

        CoderCommon();

        virtual ~CoderCommon();

        j_common_ptr getCInfoPtr();

        virtual CoderCommon* initCoder();

        virtual void setErrorHandler(JPEG::ImageCodecErrorHandler* errorHandler);

        virtual void error(int code);
        virtual void warn(int code);

        virtual std::string lastErrorMsg();
        virtual int lastErrorCode();

        virtual int start() = 0;
        virtual int finish() = 0;

        virtual void close() = 0;
    };

    class Encoder : public CoderCommon,public JPEG::Encoder{
    private:
        jpeg_compress_struct cc;
        DestinationManager* destinationManager;
    protected:
        virtual j_common_ptr init_private() ;
    public:
        Encoder();
        ~Encoder();

        j_compress_ptr getCompressPtr();

        virtual DestinationManager* getDestinationManager();

        virtual void setOutput(JPEG::ImageOutputStream* output);
        virtual int writeScanLines(int lines,JPEG::ImageInputStream* in);

        virtual void setErrorHandler(JPEG::ImageCodecErrorHandler* errorHandler);
        virtual void error(int code);
        virtual void warn(int code);
        virtual std::string lastErrorMsg();
        virtual int lastErrorCode();

        virtual int start();
        virtual int finish();
        virtual void close();
        virtual void setDefault();


        DECLARE_GETTER_SETTER(JDIMENSION,image_width);
        DECLARE_GETTER_SETTER(JDIMENSION,image_height);
        DECLARE_GETTER_SETTER(int,input_components);
        DECLARE_GETTER_SETTER(J_COLOR_SPACE,in_color_space);
        DECLARE_GETTER_SETTER(double,input_gamma);
        DECLARE_GETTER_SETTER(boolean,lossless);
        DECLARE_GETTER_SETTER(int,data_precision);

        DECLARE_GETTER_SETTER(int,num_components)
        DECLARE_GETTER_SETTER(J_COLOR_SPACE ,jpeg_color_space)
        DECLARE_GETTER_SETTER(int ,num_scans)
        DECLARE_GETTER_SETTER(boolean ,raw_data_in)
        DECLARE_GETTER_SETTER(boolean, arith_code)
        DECLARE_GETTER_SETTER(boolean, optimize_coding)
        DECLARE_GETTER_SETTER(boolean, CCIR601_sampling)
        DECLARE_GETTER_SETTER(int, smoothing_factor)

        DECLARE_GETTER_SETTER(unsigned int,restart_interval)
        DECLARE_GETTER_SETTER(int,restart_in_rows)

        DECLARE_GETTER_SETTER(boolean,write_JFIF_header)
        DECLARE_GETTER_SETTER(UINT8,JFIF_major_version)
        DECLARE_GETTER_SETTER(UINT8,JFIF_minor_version)

        DECLARE_GETTER_SETTER(UINT8,density_unit)
        DECLARE_GETTER_SETTER(UINT16,X_density)
        DECLARE_GETTER_SETTER(UINT16,Y_density)
        DECLARE_GETTER_SETTER(boolean,write_Adobe_marker)

        DECLARE_GETTER_SETTER(JDIMENSION,next_scanline)
        DECLARE_GETTER_SETTER(int,data_unit)
        DECLARE_GETTER_SETTER(J_CODEC_PROCESS,process)

        DECLARE_GETTER_SETTER(int,max_h_samp_factor)
        DECLARE_GETTER_SETTER(int,max_v_samp_factor)

        DECLARE_GETTER_SETTER(JDIMENSION,total_iMCU_rows)
        DECLARE_GETTER_SETTER(int,comps_in_scan)
        DECLARE_GETTER_SETTER(JDIMENSION,MCUs_per_row)
        DECLARE_GETTER_SETTER(JDIMENSION,MCU_rows_in_scan)
        DECLARE_GETTER_SETTER(int,data_units_in_MCU)
        DECLARE_GETTER_SETTER(int,Ss)
        DECLARE_GETTER_SETTER(int,Se);
        DECLARE_GETTER_SETTER(int,Ah);
        DECLARE_GETTER_SETTER(int,Al);


        virtual void quality(int v);
        virtual void lossy(bool l);


    };

    class Decoder : public CoderCommon,public JPEG::Decoder {
    private:
        jpeg_decompress_struct dc;
        SourceManager* sourceManager;

    protected:
        virtual j_common_ptr init_private() ;

    public:
        virtual ~Decoder();
        j_decompress_ptr getDecompressPtr();

        virtual SourceManager* getSourceManager();
        virtual void setInput(JPEG::ImageInputStream* input);

        virtual void setErrorHandler(JPEG::ImageCodecErrorHandler* errorHandler);
        virtual void error(int code);
        virtual void warn(int code);
        virtual std::string lastErrorMsg();
        virtual int lastErrorCode();

        virtual int readHeader(bool require_image);
        virtual int readScanLines(int lines,JPEG::ImageOutputStream* out);

        virtual int start();
        virtual int finish();
        virtual void close();

        DECLARE_GETTER_SETTER(JDIMENSION ,image_width)
        DECLARE_GETTER_SETTER(JDIMENSION ,image_height)
        DECLARE_GETTER_SETTER(int ,num_components)
        DECLARE_GETTER_SETTER(J_COLOR_SPACE ,jpeg_color_space)
        DECLARE_GETTER_SETTER(J_COLOR_SPACE ,out_color_space)
        DECLARE_GETTER_SETTER(unsigned int ,scale_num)
        DECLARE_GETTER_SETTER(unsigned int,scale_denom)
        DECLARE_GETTER_SETTER(double ,output_gamma)
        DECLARE_GETTER_SETTER(boolean ,buffered_image)
        DECLARE_GETTER_SETTER(boolean ,raw_data_out)
        DECLARE_GETTER_SETTER(J_DCT_METHOD ,dct_method)
        DECLARE_GETTER_SETTER(boolean ,do_fancy_upsampling)
        DECLARE_GETTER_SETTER(boolean ,do_block_smoothing)
        DECLARE_GETTER_SETTER(boolean ,quantize_colors)
        DECLARE_GETTER_SETTER(J_DITHER_MODE ,dither_mode)
        DECLARE_GETTER_SETTER(boolean ,two_pass_quantize)
        DECLARE_GETTER_SETTER(int ,desired_number_of_colors)
        DECLARE_GETTER_SETTER(boolean ,enable_1pass_quant)
        DECLARE_GETTER_SETTER(boolean ,enable_external_quant)
        DECLARE_GETTER_SETTER(boolean ,enable_2pass_quant)
        DECLARE_GETTER_SETTER(JDIMENSION ,output_width)
        DECLARE_GETTER_SETTER(JDIMENSION ,output_height)
        DECLARE_GETTER_SETTER(int ,out_color_components)
        DECLARE_GETTER_SETTER(int ,output_components)
        DECLARE_GETTER_SETTER(int ,rec_outbuf_height)
        DECLARE_GETTER_SETTER(int ,actual_number_of_colors)
        DECLARE_GETTER_SETTER(JDIMENSION ,output_scanline)
        DECLARE_GETTER_SETTER(int ,input_scan_number)
        DECLARE_GETTER_SETTER(JDIMENSION ,input_iMCU_row)
        DECLARE_GETTER_SETTER(int ,output_scan_number)
        DECLARE_GETTER_SETTER(JDIMENSION ,output_iMCU_row)
        DECLARE_GETTER_SETTER(int ,data_precision)
        DECLARE_GETTER_SETTER(boolean ,saw_JFIF_marker)
        DECLARE_GETTER_SETTER(UINT8 ,JFIF_major_version)
        DECLARE_GETTER_SETTER(UINT8 ,JFIF_minor_version)
        DECLARE_GETTER_SETTER(UINT8 ,density_unit)
        DECLARE_GETTER_SETTER(UINT16 ,X_density)
        DECLARE_GETTER_SETTER(UINT16 ,Y_density)
        DECLARE_GETTER_SETTER(boolean ,saw_Adobe_marker)
        DECLARE_GETTER_SETTER(UINT8 ,Adobe_transform)
        DECLARE_GETTER_SETTER(boolean ,CCIR601_sampling)
        DECLARE_GETTER_SETTER(int ,data_unit)
        DECLARE_GETTER_SETTER(J_CODEC_PROCESS ,process)
        DECLARE_GETTER_SETTER(int ,max_h_samp_factor)
        DECLARE_GETTER_SETTER(int ,max_v_samp_factor)
        DECLARE_GETTER_SETTER(int ,min_codec_data_unit)
        DECLARE_GETTER_SETTER(JDIMENSION ,total_iMCU_rows)
        DECLARE_GETTER_SETTER(JDIMENSION, MCUs_per_row)
        DECLARE_GETTER_SETTER(JDIMENSION ,MCU_rows_in_scan)
        DECLARE_GETTER_SETTER(int ,data_units_in_MCU)
        DECLARE_GETTER_SETTER(int,Ss)
        DECLARE_GETTER_SETTER(int ,Se)
        DECLARE_GETTER_SETTER(int ,Ah)
        DECLARE_GETTER_SETTER(int,Al)
        DECLARE_GETTER_SETTER(int,unread_marker)
    };


};


#endif //PEGBITCOMMON_H
